package com.woniuxy.oa.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GetOvertimeUtils {
	//测试代码
	public static void main(String[] args) throws ParseException {
		String start = "2019-07-15 10:00:00";
	    String end = "2019-07-15 18:30:00";
	    String countTime = countTime(start, end);
	    System.out.println(countTime);
	}
	
	//封装方法
	public static String countTime(String begin,String end){  
	    int hour = 0;  
	    int minute = 0;  
	    long total_minute = 0;  
	    StringBuffer sb = new StringBuffer();  
	  
	    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
	    try {  
	        Date begin_date = df.parse(begin);  
	        Date end_date = df.parse(end);  
	  
	        total_minute = (end_date.getTime() - begin_date.getTime())/(1000*60);  
	  
	        hour = (int) total_minute/60;  
	        minute = (int) total_minute%60;  
	  
	    } catch (ParseException e) {  
	        System.out.println("传入的时间格式不符合规定");  
	    }  
	  
	    sb.append(hour).append("小时").append(minute).append("分钟");  
	    return sb.toString();  
	}  
	
}
